package com.md01.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

@Component
@MapperScan("com.md01.mapper")
public class MybatisConfig {
    //1、先写注解
//    @Component
//    @MapperScan("com.md01.mapper")

    //2、写SSF方法,加入形参，在new一个 SqlSessionFactoryBean()

    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        return sqlSessionFactoryBean;

    }


}
